package db

import (
	"go.mongodb.org/mongo-driver/bson"
	persis "my-gameserver-go/logic/persistenceObj"
)

var PlayerAccess *PlayerDBAccess

type PlayerDBAccess struct {
	DBConn *MongoDbConn
}

func (p *PlayerDBAccess) Save(saveObj BaseSaveObj) {
	p.DBConn.Save(saveObj)
}

func (p *PlayerDBAccess) findById(playerId int64) *persis.Player {
	player := &persis.Player{}
	success := p.DBConn.FindOne(bson.M{"playerId": playerId}, player)
	if success {
		return player
	}
	return nil
}
func (p *PlayerDBAccess) FindPlayerByUserId(userId int64) *persis.Player {
	player := &persis.Player{}
	success := p.DBConn.FindOne(bson.M{"userId": userId}, player)
	if success {
		return player
	}
	return nil
}
func (p *PlayerDBAccess) HasPlayerByUserId(userId int64) (bool, error) {
	player := &persis.Player{}
	return p.DBConn.HasObj(bson.M{"userid": userId}, player)
}
